
;; customize default functions
(defadvice before printout
    (bind ?tail (rest$ ?argv))
    (bind ?argv (create$ printout t "jess> " ?tail crlf
            )))

;; import java packages
(import sketch.doc.*)
(import sketch.ink.*)
(import sketch.parse.*)
(import sketch.shape.*)
(import sketch.shape.arrow.*)
(import sketch.shape.geom.*)
(import sketch.shape.geom.prim.*)

;; fetch shapes
(bind ?sketch (fetch "SKETCH"))

;; facts ==================================================
(deftemplate shape
    "shape structure"
    (slot name)
    (slot obj)
    (multislot children))

;; functions ==============================================
(deffunction init-facts ()
    "init facts"
	(bind ?it ((?sketch getShapes) iterator))
    (while (?it hasNext)
        (bind ?o (?it next))
        (assert (shape
                (name (?o getName))
                (obj ?o)))))

(deffunction list-children ($?chn)
    "generate list from children"
    (bind ?list (new java.util.ArrayList))
    (foreach ?ch ?chn
        (?list add ?ch))
    (return ?list))

(deffunction recognize (?s ?list)
	"recognize new symbol"
	(?sketch replaceShapesBy ?list ?s))

